#ifndef EDITORTABWIDGET_H
#define EDITORTABWIDGET_H

#include <QTabWidget>
#include "editorexitdialog.h"
#include "texteditor.h"

class TextEditorsManager : public QTabWidget
{
    Q_OBJECT
public:
    TextEditorsManager(QWidget *parent = 0);

    QList<TextEditor *> editors() const;
    TextEditor * editor(int index) const { return static_cast<TextEditor*>(QTabWidget::widget(index)); }
    TextEditor * currentEditor() const { return currentEditor_; }

private:
    TextEditor * currentEditor_;
    
signals:
    void redoAvailable(bool);
    void undoAvailable(bool);
    void copyAvailable(bool);

public slots:
    void newFile();
    void openFile();
    void saveFile();
    void saveAs();
    void saveAll();
    void closeFile(int index) { onTabCloseRequested(index); }
    void undo() { currentEditor_->undo(); }
    void redo() { currentEditor_->redo(); }
    void cut() { currentEditor_->cut(); }
    void copy() { currentEditor_->copy(); }
    void paste() { currentEditor_->paste(); }
    void selectAll() { currentEditor_->selectAll(); }

private slots:
    void onTabCloseRequested(int index);
    void onTextChanged(bool modified);
    void updateCurrentEditor(int index);
};

#endif // EDITORTABWIDGET_H
